package com.bjut.vendormgrsys.constant;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import java.util.ArrayList;
import java.util.List;

public class Constant {

    public enum RoleEnum {
        ROLE_VENDOR("ROLE_VENDOR", "会员"),
        ROLE_ADMIN("ROLE_ADMIN", "超管"),
        ROLE_HRBP("ROLE_HRBP", "管理员"),
        ROLE_VISITOR("ROLE_VISITOR", "游客");

        private String key;
        private String desc;

        RoleEnum(String key, String desc) {
            this.key = key;
            this.desc = desc;
        }

        public String getKey() {
            return key;
        }

        public String getDesc() {
            return desc;
        }
    }

    public enum PositionStatus {
        PUBLISHING("PUBLISHING", "进行中"),
        REVOKED("REVOKED", "已完成"),
        ALL("ALL", "全部");

        private String key;
        private String name;

        PositionStatus(String key, String name) {
            this.key = key;
            this.name = name;
        }

        public String getKey() {
            return key;
        }

        public void setKey(String key) {
            this.key = key;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

    public enum ResumeStatus {
        RECOMMENDING("RECOMMENDING", "推荐中"),
        REFUSE("REFUSE", "拒绝"),
        PASS("PASS", "通过"),
        ALL("ALL", "全部");

        private String key;
        private String name;

        ResumeStatus(String key, String name) {
            this.key = key;
            this.name = name;
        }

        public String getKey() {
            return key;
        }

        public void setKey(String key) {
            this.key = key;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

    public enum UserStatus {
        DISABLE("DISABLE", "已停止"),
        ENABLE("ENABLE", "活跃"),
        ALL("ALL", "全部");

        private String key;
        private String name;

        UserStatus(String key, String name) {
            this.key = key;
            this.name = name;
        }

        public String getKey() {
            return key;
        }

        public void setKey(String key) {
            this.key = key;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public static String getNameByKey(String key){
            try {
                String name = UserStatus.valueOf(key).getName();

                return name;
            } catch (IllegalArgumentException e) {
                throw new RuntimeException("状态不存在：" + key);
            }
        }
    }

    public enum AuditStatus {
        WAIT("WAIT", "待审核"),
        PASS("PASS", "审核通过"),
        NOTPASS("NOTPASS", "审核不通过"),
        NOAUDIT("NOAUDIT", "不需要审核"), // 当某个请求取消的时候
        ALL("ALL", "全部");

        private String key;
        private String name;

        AuditStatus(String key, String name) {
            this.key = key;
            this.name = name;
        }

        public String getKey() {
            return key;
        }

        public void setKey(String key) {
            this.key = key;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public static String getNameByKey(String key){
            try {
                String name = AuditStatus.valueOf(key).getName();

                return name;
            } catch (IllegalArgumentException e) {
                throw new RuntimeException("状态不存在：" + key);
            }
        }
    }

    public enum CampaignStatus {
        NEW("NEW", "新建"),
        RECRUITING("RECRUITING", "招募期"),
        COMPLETED("COMPLETED", "招募完成"),
        CANCELLED("CANCELLED", "取消"),
        REFUSE("REFUSE", "拒绝");

        private String key;
        private String name;

        CampaignStatus(String key, String name) {
            this.key = key;
            this.name = name;
        }

        public String getKey() {
            return key;
        }

        public void setKey(String key) {
            this.key = key;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public static String getNameByKey(String key){
            try {
                String name = CampaignStatus.valueOf(key).getName();

                return name;
            } catch (IllegalArgumentException e) {
                throw new RuntimeException("状态不存在：" + key);
            }
        }
    }

    public enum NewsStatus {
        NEW("NEW", "待发布"),
        PUBLISHED("PUBLISHED", "已发布"),
        REVOKE("REVOKE", "已下线");

        private String key;
        private String name;

        NewsStatus(String key, String name) {
            this.key = key;
            this.name = name;
        }

        public String getKey() {
            return key;
        }

        public void setKey(String key) {
            this.key = key;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public static String getNameByKey(String key){
            try {
                String name = NewsStatus.valueOf(key).getName();

                return name;
            } catch (IllegalArgumentException e) {
                throw new RuntimeException("状态不存在：" + key);
            }
        }
    }

    public static String getPositionStatusName(String key) {
        if (PositionStatus.PUBLISHING.getKey().equals(key)) {
            return PositionStatus.PUBLISHING.getName();
        } else if (PositionStatus.REVOKED.getKey().equals(key)) {
            return PositionStatus.REVOKED.getName();
        } else if (PositionStatus.ALL.getKey().equals(key)) {
            return PositionStatus.ALL.getName();
        } else {
            throw new RuntimeException("职位状态不存在：" + key);
        }
    }

    public static String getResumeStatusName(String key) {
        if (ResumeStatus.RECOMMENDING.getKey().equals(key)) {
            return ResumeStatus.RECOMMENDING.getName();
        } else if (ResumeStatus.REFUSE.getKey().equals(key)) {
            return ResumeStatus.REFUSE.getName();
        } else if (ResumeStatus.PASS.getKey().equals(key)) {
            return ResumeStatus.PASS.getName();
        } else if (ResumeStatus.ALL.getKey().equals(key)) {
            return ResumeStatus.ALL.getName();
        } else {
            throw new RuntimeException("简历状态不存在：" + key);
        }
    }

    public static Pageable getPageable(Integer offset, Integer max) {
        int page = 1;
        int size = 10;
        if (offset != null && max != null) {
            page = offset / max + 1;
            size = max;
        }
        page -= 1;
        return PageRequest.of(page, size, Sort.Direction.DESC, "lastUpdated");
    }

}
